<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/pravate/detail.css" />
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../js/config.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js" ></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<!--<script type="text/javascript" src="../controll/depositDetail.js"></script>-->
		<script type="text/javascript" src="../js/template-web.js"></script>
	</head>
	<style type="text/css">
		body,
		html {
			overflow-x: hidden;
		}
		
		.mui-input-row label {
			font-size: 14px;
			width: 35%;
			text-align: justify;
			text-align-last: justify;
			line-height: 0;
		}
		
		.mui-input-row label~input,
		.mui-input-row label~select,
		.mui-input-row label~textarea {
			font-size: 14px;
			width: 65%;
		}
		
		.detail_logo {
			height: 7rem;
		}
		
		.detail_logo img {
			height: 80px;
			padding-top: 30px;
		}
		
		.mui-input-group .mui-button-row {
			height: auto;
			padding: 15px 20px;
		}
		
		.beizhu {
			display: block;
			font-size: 14px;
			color: #000 !important;
			border: 1px solid #C9C9C9 !important;
			width: 88%;
			margin: 0 auto;
			height: 55px;
		}
		
		.mui-popup-text p {
			text-align: left;
		}
		
		.mui-popup-text p label {
			display: inline-block;
			text-align: center;
			width: 40%;
		}
		
		.active_dis {
			display: none;
		}
		
		.settle:after,
		.beizhu1:after {
			height: 0 !important;
		}
		
		.beizhu1 {
			height: auto !important;
			padding: 10px 0;
		}
		
		.settle {
			padding-right: 23px !important;
		}
		
		.pay_settle {
			border: 1px solid #FFCC00 !important;
			padding-left: 10px !important;
		}
		
		.mui-btn-block {
			padding: 5px 0;
		}
		
		.depPrice {
			color: red;
			font-size: 24px;
		}
		
		.pay_licensing {
			font-size: 18px !important;
			color: red;
		}
		
		.mui-input-row label {
			line-height: 1.4;
		}
		
		.bzxx {
			padding-right: 50px;
		}
		
		.changeBz {
			position: absolute;
			right: 5px;
			top: 1px;
			padding: 10px 0 !important;
			width: 55px !important;
		}
		
		.mui-input-group .but {
			padding-left: 0;
			padding-right: 0;
		}
		
		.but button:last-child {
			height: 52px;
			font-size: 20px;
		}
		
		.returnTitle {
			color: #FFF;
			font-size: 20px;
			width: 100%;
			height: 55px;
			background-color: red;
			padding: 15px;
		}
		
		.returnTitle span {
			font-size: 26px;
			font-weight: 900;
			margin-right: 15px;
		}
		#payresult{
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, 0.3);
			position: fixed;
			left:0;
			top: 0;
			z-index: 9999;
			text-align: center;
			padding: 60px;
			display: none;
		}
		.payCentent{
			background: #fff;
			padding: 15px 0;
			width: 260px;
			height: 110px;
			border-radius: 10px;
			position: absolute;
			left: 50%;
			top: 50%;
			margin-top: -55px;
			margin-left: -130px;
		}
		.payCentent .mui-btn{
			margin-top: 15px;
		}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">交易详情</h1>
			<span class="refund">打印</span>
		</header>
		<div id="payresult" style="z-index: 99999;">
			<div class="payCentent">
				<h5>正在进行预授权撤销</h5>
				<div>
					<button type="button" class="merge mui-btn mui-btn-primary mui-btn-outlined">操作完成</button>
				</div>
			</div>
		</div>
		<div class="mui-content">
			<script type="text/html" id="model">
				{{if status=="success"}}
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label>交易订单号：</label>
						<input class="order_id" value="{{data[0].out_order_no}}" type="text" disabled="disabled" placeholder="">
					</div>
					<div class="mui-input-row">
						<label>交易流水号：</label>
						<input class="serial_id" value="{{data[0].auth_no}}" type="text" disabled="disabled" placeholder="">
					</div>
					<div class="mui-input-row">
						<label>消费账户：</label>
						<input class="pay_account" value="{{data[0].payer_logon_id}}" type="text" disabled="disabled">
					</div>
					<div class="mui-input-row">
						<label>消费时间：</label>
						<input class="pay_time" value="{{data[0].created_at}}" type="text" disabled="disabled">
					</div>
					<div class="mui-input-row">
						<label>预授权金额：</label>
						<input class="pay_licensing" type="text" disabled="disabled" placeholder="" value="{{data[0].amount}}元">
					</div>
					<div class="mui-input-row">
						<label>消费金额：</label>
						<input class="use_price" value="{{data[0].pay_amount}}" type="text" disabled="disabled" placeholder="">
					</div>
					<div class="mui-input-row">
						<label>结算状态：</label>
						<input class="pay_status" value="{{pay_status(data[0].pay_status)}}" type="text" disabled="disabled">
						{{if asycsP == '1'}}
							<button type="button" class="mui-btn mui-btn-warning asycs" data-id='{{data[0].out_order_no}}' style="z-index: 100;position: absolute;right: 10px;width: 85px;">同步状态</button>
						{{/if}}
					</div>
					<div class="mui-input-row">
						<label>备注信息：</label>
						<input class="bzxx" value="{{data[0].fu_remark}}" type="text" disabled="disabled">
						<button type="button" class="mui-btn mui-btn-success changeBz" data-id='{{data[0].out_order_no}}' style="z-index: 100;position: absolute;right: 10px;width: 85px;">修改</button>
					</div>
					<div style="width: 100%;height: 10px;background-color: #EFEFF4;"></div>
					{{if fromTo != 'overTime'}}
						<div class="mui-input-row settle" style="padding: 5px 0;">
							<label>消费金额：</label>
							<input class="pay_settle" type="number" value="" placeholder="请输入消费金额" style="height: 35px;padding: 7px 10px;color: red;font-size: 16px;">
						</div>
						<div class="mui-input-row beizhu1">
							<textarea class="beizhu remarks_info" style="" rows="3" placeholder="请输入备注信息"></textarea>
						</div>
						<div class="mui-button-row but">
							<button type="button" class="mui-btn mui-btn-warning thaw mui-col-xs-4">预授权</br>撤销</button>
							<span class="mui-col-xs-1" style="height: 10px;display: inline-block;"></span>
							<button type="button" class="mui-btn mui-btn-success checkout mui-col-xs-7">结算</button>
						</div>
					{{/if}}
				</form>
				{{/if}}
				{{if fromTo == 'overTime'}}
					<p style="margin-bottom: 0;padding-left: 15px;font-size: 14px;padding-top: 5px;">查看关联订单</p>
					<ul class="mui-table-view guanlian">
					    <li class="mui-table-view-cell" data-order='{{replaceStr(data[0].out_order_no)}}' style="padding: 0 0 0 8px;font-size: 14px;line-height: 45px;position: relative;">
					        <a class="mui-navigate-right">预授权结算-{{replaceStr(data[0].out_order_no)}}</a>
					        <span style="position: absolute;bottom: -1px;right: 30px;z-index: 999;"></span>
					    </li>
					</ul>
				{{/if}} 
			</script>
		</div>
		<script>
			$(document).ready(function() {
				mui.init();
				mui('body').on('tap','.merge',function(){
					window.location.reload();
				})
				mui.plusReady(function() {
					plus.nativeUI.showWaiting("数据加载中...");
					var wx = plus.webview.currentWebview();
					var signx = false;
					var hl = $(document).innerHeight();
					var dayin_sign = false;
					var remark_s = "";
					$("html, body").height(hl + "px");
					var token = localStorage.getItem("token");
					var order_type="";
					//交易状态
					template.defaults.imports.pay_status = function(num) {
						var sta = "";
						switch(num) {
							case 1:
								sta = "未结算";
								break;
							case 2:
								sta = "已取消";
								break;
							case 3:
								sta = "等待支付";
								break;
							case 4:
								sta = "已结算";
								break;
							case 5:
								sta = "已退回";
								break;
						}
						return sta;
					}
					
					mui('body').on('tap', '.guanlian li', function(){
						console.log($(this).attr('data-order'));
						mui.openWindow({
							url:"detail.html",
							id:"detail.html",
							extras:{
								orderNum:$(this).attr('data-order')
							}
						})
					})
					
					// 点击状态同步
					var asycsSign = false;
					mui('body').on('tap', '.asycs', function () {
						if (asycsSign) {
							return false;
						}
						asycsSign = true;
						plus.nativeUI.showWaiting('正在同步状态，请稍候');
						bs_pay({
							token: localStorage.getItem('token'),
							amount: '',
							barcodeType: '',
							orderInfo: '',
							orderNoSFT: $(this).attr('data-id'),
							payCallUrl: '',
							remark: ''
						},"17");
						setTimeout(function(){
							plus.nativeUI.closeWaiting();
							asycsSign = false;
							window.location.reload();
						}, 5000);
					})
					
					template.defaults.imports.replaceStr = function(str) {
						return str.replace('fu', 'f');
					}
					var asycsP = true;
					if(getSysInfo().search("P1") == -1) {
						asycsP = false;
					};
					console.log(JSON.stringify(wx))
					require(weburl + model_fundAuthLists, "json", "post", {
						token: token,
						type: "901",
						auth_no: wx.authNo,
						out_order_no: wx.orderNum
					}, function(response) {
						console.log(JSON.stringify(response));
						response.fromTo = wx.fromTo;
						//如果是P1 则为1
						response.asycsP = asycsP ? '1' : '0';
						var html = template("model", response);
						$(".mui-content").html(html);
						plus.nativeUI.closeWaiting();
						var data = response.data[0];
						order_type=data.type;
						Bluetooth();
						//点击结算按钮
						mui("body").on("tap", ".checkout", function() {
							$(".remarks_info, .pay_settle").blur();
							console.log(JSON.stringify(response));
							if (response.data[0].pay_status !== 1) { //订单状态不合法
								mui.alert('该订单已完成,无法继续操作',' ','关闭',function(){},'div');
								return;
							}
							if(data.pay_status == 1 && $(".remarks_info").val() && $(".pay_settle").val()) {
								var res=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
								console.log(res.test($(".pay_settle").val()));
								if (!res.test($(".pay_settle").val())) {
									mui.alert("消费金额格式不正确，请重新输入"," ","关闭",function(){},"div");
									return false;
								}
								
								//弹出框内容
								var str = "<p><label>预授权金额：</label><span class='depPrice'>" + data.amount + "</span>元</p><p><label>消费金额：</label><span class='depPrice'>" + Number($(".pay_settle").val()).toFixed(2) + "</span>元</p><p><label>消费时间：</label>" + data.created_at + "</p><p><label>备注信息：</label>" + $(".remarks_info").val() + "</p>";
								str+="<p style='font-size:16px;text-align:center;color:red;'>请确认消费金额是否与实际消费一致？</p>"; 
								str+="<p style='text-align:center;margin-top:15px;font-size:16px;color:#F0AD4E;margin-bottom:0;padding-bottom:10px;'>一旦操作，剩余资金将解冻退回</br>无法被追回</p>";
								mui.confirm(str, "确认结算？", ["确认结算", "取消"], function(e) {
									if(e.index == 0) {
										if(order_type==902){  //如果是银联卡结算
											require(weburl+BankOrderCreate,"json","post",{
												token:localStorage.getItem("token"),
												amount:$(".pay_settle").val(),
												pay_type:"auth",
												remark:$(".remarks_info").val(),
												authtype:2,
												orderid:data.out_order_no
											},function(auth_res){
												if(auth_res.status=="success"){
													//调用sdk
												   	bs_pay({
												   		'token': localStorage.getItem("token"),
													   	"amount":auth_res.data[0].amount,
												    	"barcodeType":"0",
												    	"orderInfo":$(".remarks_info").val(),
												    	"orderNoSFT":auth_res.data[0].out_trade_no,
												    	"transDate":auth_res.data[0].transDate,
												    	"traceNo":auth_res.data[0].traceNo,
												    	"authNo":auth_res.data[0].authNo,
												    	"payCallUrl":callbackUrl,
												    	'remark': auth_res.data[0].remark?auth_res.data[0].remark:''
												   	},"4");
												   	$('.payCentent h5').html('正在进行预授权结算');
												   	$('#payresult').css('display','block');
												} else {
													mui.alert(auth_res.msg,"","关闭",function(){},"div");
												}
											},function(xhr){
												console.log(JSON.stringify(xhr));
											})
										} else {
											plus.nativeUI.showWaiting("正在结算中，请勿退出...");
											require(weburl + model_FundAuthTrade, "json", "post", {
												token: token,
												remarks: $(".remarks_info").val(),
												pay_num: $(".pay_settle").val(),
												auth_no: data.auth_no
											}, function(re) {
												console.log(JSON.stringify(re));
												if(re.status == "success") {
													var str = re.data[0].print_body;
													var reg = /\\n/g;
													str = str.replace(reg, '\n');
													printTicket(re.data[0].print_array);
													plus.nativeUI.closeWaiting();
													mui.closePopups();
													mui.confirm("结算成功，是否打印小票？", " ", ["打印", "关闭"], function(e) {
														if(e.index == 0) {
															if(signx == false) {
																console.log(re.data[0].print_array);
																printTicket(re.data[0].print_array);
	//															ticket(re.data[0].store_name, str, re.data[0].out_trade_no);
																signx = true;
																setTimeout(function() {
																	signx = false;
																}, 3000);
															}
															return false;
														} else {
															window.location.reload();
														}
	
													}, "div");
												} else {
													plus.nativeUI.closeWaiting();
													mui.alert(re.msg, " ", "关闭", function() {}, "div");
												}
											}, function() {
												plus.nativeUI.closeWaiting();
												mui.alert("请求错误，请稍后再试", " ", "关闭", function() {}, "div");
											})
										}
									}
								}, "div");
							} else if(!$(".pay_settle").val()) {
								mui.alert("<p style='text-align:center;font-size:16px;color:#000;'>消费金额不能为空！</p>", " ", "确认", function() {}, "div");
							} else if(!$(".remarks_info").val()) {
								mui.alert("<p style='text-align:center;font-size:16px;color:#000;'>备注信息不能为空！</p>", " ", "确认", function() {}, "div");
							} else {
								mui.alert("该订单已关闭", " ", "确定", function() {}, "div");
							}
						})

						//点击预授权撤销
						mui("body").on("tap", ".thaw", function() {
							$(".remarks_info, .pay_settle").blur();
							if (response.data[0].pay_status !== 1) { //订单状态不合法
								mui.alert('该订单已完成,无法继续操作',' ','关闭',function(){},'div');
								return;
							}
							var signx = false;
							//输入框内容
							var conf = "<p class='returnTitle' style='text-align:center;'><span class='mui-icon mui-icon-info'></span>警告！</p>";
							conf += "<p style='font-size:16px;text-align:center;'>退回金额：<span style='font-size:18px;color:red;'>" + data.amount + "<span>元</p>";
							conf += "<p style='font-size:16px;text-align:center;color:red;'>请确认客户没有消费！</p>";
							conf += "<p style='text-align:center;margin-top:15px;font-size:16px;color:#F0AD4E;'>一旦退回，资金将无法被追回</br>请谨慎操作</p>";
							//预授权模板
							var str = "<p><label>预授权金额：</label><span class='depPrice'>" + data.amount + "</span>元</p><p><label>消费时间：</label>" + data.created_at + "</p><p><label>备注信息：</label>" + $(".remarks_info").val() + "</p><p><label>支付密码：</label><input class='pay_settle pay_pas' type='password' placeholder='请输入支付密码' style='font-size:12px;'></p>";
							if($(".remarks_info").val()) { //弹出第一个框
								mui.confirm(conf, " ", ["确认", "取消"], function(ev) {
									if(ev.index == 0) { //如果内容不为空且点击确认按钮
										if(order_type==902){  //如果是银联卡撤销
											console.log(JSON.stringify(data));
											require(weburl+BankFundAuthOrderUnfreeze,"json","post",{
												token:localStorage.getItem("token"),
												orderid:data.out_order_no,
												remark:$(".remarks_info").val()
											},function(auth_freeze){
												if(auth_freeze.status=="success"){
													bs_pay({
														'token': localStorage.getItem("token"),
														"amount":auth_freeze.data[0].amount,
												    	"barcodeType":"0",
												    	"orderInfo":$(".remarks_info").val(),
												    	"orderNoSFT":auth_freeze.data[0].out_trade_no,
												    	"transDate":auth_freeze.data[0].transDate,
												    	"traceNo":auth_freeze.data[0].traceNo,
												    	"authNo":auth_freeze.data[0].authNo,
												    	"payCallUrl":callbackUrl,
												    	'remark': auth_freeze.data[0].remark?auth_freeze.data[0].remark:''
													},5);
													$('.payCentent h5').html('正在进行预授权撤销');
													$('#payresult').css('display','block');
												} else {
													mui.alert(auth_freeze.msg,"","关闭",function(){},"div");
												}
											},function(xhr){
												console.log(JSON.stringify(xhr));
											})
										} else {
											$(".mui-popup-inner").css("padding", "15px");
											mui.confirm(str, "确认解冻退回？", ["取消", "全额退回"], function(e) {
												$(".pay_pas").blur();
												if(e.index == 1) { //点击全额退回
													var remark_i = $(".remark_i").val();
													var pay_pas = $(".pay_pas").val();
	
													if($(".pay_pas").val()) {
														plus.nativeUI.showWaiting("预授权撤销中，请勿退出...");
														require(weburl + model_Unfreeze, "json", "post", {
															token: token,
															paystr: $(".pay_pas").val(),
															auth_no: data.auth_no,
															remarks: $(".remarks_info").val()
														}, function(res) {
															if(res.status == "success") {
																console.log(JSON.stringify(response));
																var str = res.data[0].print_body;
																var reg = /\\n/g;
																str = str.replace(reg, '\n');
																printTicket(res.data[0].print_array);
																plus.nativeUI.closeWaiting();
	//															ticket(res.data[0].store_name, str, res.data[0].out_trade_no + "-");
																mui.closePopups();
																mui.confirm("解冻退回成功，是否打印小票？", " ", ["打印", "关闭"], function(e) {
																	if(e.index == 0) {
																		if(signx == false) {
																			printTicket(res.data[0].print_array);
	//																		ticket(res.data[0].store_name, str, res.data[0].out_trade_no + "-");
																			signx = true;
																			setTimeout(function() {
																				signx = false;
																			}, 3000);
																		}
																	} else {
																		window.location.reload();
																	}
	
																}, "div");
															} else {
																mui.closePopups();
																plus.nativeUI.closeWaiting();
																mui.alert(res.msg, " ", "关闭", function() {}, "div");
															}
														}, function() {
															plus.nativeUI.closeWaiting();
															mui.closePopups();
															mui.alert("请求错误，请稍后再试", " ", "关闭", function() {}, "div");
														})
													} else if(!$(".pay_pas").val()) {
														mui.alert("<p style='text-align:center;font-size:16px;color:#000;'>支付密码不能为空！</p>", " ", ["确认"], function() {}, "div");
													}
												}
											}, "div");
										}
									}
								}, "div");
								$(".mui-popup-inner").css("padding", "0");
								$(".mui-popup-inner").css("padding-bottom", "15px");
							} else {
								mui.alert("<p style='text-align:center;font-size:16px;color:#000;'>备注信息不能为空！</p>", " ", ["确认"], function() {}, "div");
							}

						})

					}, function() {
						plus.nativeUI.closeWaiting();
						mui.alert("系统繁忙，请稍后重试");
					})

					//点击打印按钮
					mui("body").on("tap", ".refund", function() {
						plus.nativeUI.showWaiting("正在打印中，请勿退出");
						require(weburl + model_shouquandayin, "json", "post", {
							token: localStorage.getItem("token"),
							out_order_no: $(".order_id").eq(0).val(),
							auth_no: wx.authNo
						}, function(response) {
							plus.nativeUI.closeWaiting();
							if(response.status == "success") {
								var str = response.data[0].print_body;
								var reg = /\\n/g;
								str = str.replace(reg, "\n");
								mui.closePopups();
								mui.confirm("是否打印小票？", " ", ["打印", "关闭"], function(e) {
									if(e.index == 0) {
										if(dayin_sign == false) {
											console.log(JSON.stringify(response));
											printTicket(response.data[0].print_array);
//											ticket(response.data[0].store_name, str, response.data[0].out_order_no + "-");
											dayin_sign = true;
											setTimeout(function() {
												dayin_sign = false;
											}, 3000);
										}
										return false;
									} else {

									}
								}, "div");
							} else {
								mui.alert(response.msg, " ", "关闭", function() {}, "div");
							}
						}, function() {
							plus.nativeUI.closeWaiting();
							mui.alert("请求错误，请稍后再试", " ", "关闭", function() {}, "div");
						})
					})

					/*
					 * 点击修改备注
					 */
					mui("body").on("tap", ".changeBz", function() {
						//弹出输入框
						if($(".pay_status").val() == "未结算") {
							mui.confirm("<input type='text' value='" + $(".bzxx").val() + "' class='change_remark' >", "修改备注", ["确认", "取消"], function(e) {
								$(".change_remark").blur();
								if(e.index == 0 && $(".change_remark").eq(0).val()) { //点击了确认按钮并且内容不为空
									require(weburl + model_remark, "json", "post", {
										token: localStorage.getItem("token"),
										auth_no: wx.authNo,
										out_order_no: wx.orderNum,
										remarks: $(".change_remark").eq(0).val()
									}, function(response) {
										//成功函数
										mui.alert(response.msg, " ", "关闭", function() {
											if(response.status == "success") { //如果修改成功则刷新页面
												window.location.reload();
											}
										}, "div")
									}, function() {
										//失败函数
										mui.alert("修改备注信息失败", " ", "关闭", function() {}, "div");
									})
								} else if(e.index == 0 && (!$(".change_remark").eq(0).val())) {
									mui.alert("备注内容不能为空", " ", "关闭", function() {}, "div");
								}
							}, "div")
							return false;
						}
						mui.alert("该订单已完成,不可修改", " ", "关闭", function() {}, "div");

					})
				})

			})
		</script>
	</body>

</html>